﻿using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using filmquiz.Src;
using filmquiz.Src.DatabaseAccess;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        loggedInDiv.Visible = true;
        notLoggedInDiv.Visible = true;
    }

    private void Page_PreRender(object sender, System.EventArgs e)
    {
        if (Session["loggedIn"] != null)
        {
            if ((bool)Session["loggedIn"])
            {
                notLoggedInDiv.Visible = false;

                createCountDown();

                fillMessage();
            }
            else
            {
                loggedInDiv.Visible = false;
                fillNotLoggedInMessage();
            }
        }
        else
        {
            loggedInDiv.Visible = false;
            fillNotLoggedInMessage();
        }
    }

    private void createCountDown()
    {
        countDownPlaceHolder.Controls.Add(new Literal() { Text = "<script type='text/javascript' language='JavaScript'>" });
        Literal js = new Literal();
        js.Text = "TargetDate = '" +
                  QuizHelper.getInstance().getRoundById(Statics.getInstance().getCurrentRound()).end.ToString(
                      "MM/dd/yyyy hh:mm").Replace('-', '/') +
                  " AM';BackColor = '#99CCFF';ForeColor = 'black';CountActive = true;CountStepper = -1;LeadingZero = true;DisplayFormat = '%%D%% Dage, %%H%% Timer, %%M%% Minutter, %%S%% Sekunder.';FinishMessage = 'Denne runde er slut!<br />Du kan nu se alle de rigtige svar og hele statistikken på billederne';";
        countDownPlaceHolder.Controls.Add(js);
        countDownPlaceHolder.Controls.Add(new Literal() { Text = "</script>" });
    }

    private void fillMessage()
    {
        messageLabel.Text = QuizHelper.getInstance().getFrontpageMessage();
    }

    private void fillNotLoggedInMessage()
    {
        notLoggedInLabel.Text = QuizHelper.getInstance().getNotLoggedInMessage();
    }
}
